/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ytmc.uploader;

import org.apache.commons.configuration.FileConfiguration;
import ytmc.setup.*;
import ytmc.setup.security.AESPasswordCipher;
import ytmc.setup.security.PasswordCipher;

/**
 *
 * @author K
 */
public class Credentials
{
    private FileConfiguration config;
    private PasswordCipher cipher;

    private String login;

    public String getLogin()
    {
        return login;
    }

    private String password;

    public String getPassword()
    {
        return password;
    }

    public Credentials()
    {
        this.config = Config.load();
        this.cipher = new AESPasswordCipher();

        login = config.getString("login");
        password = cipher.decrypt(config.getString("password"));
    }

    @Override
    public boolean equals(Object obj)
    {
        if(obj == null)
            return false;

        if(obj == this)
            return true;

        if (obj.getClass() != getClass())
            return false;


        Credentials credentials = (Credentials)obj;

        if((this.login == null ? credentials.login == null : this.login.equals(credentials.login)) &&
           (this.password == null ? credentials.password == null : this.password.equals(credentials.password)))
        {
            return true;
        }
        else
        {
            return false;
        }
    }

    @Override
    public int hashCode()
    {
        int hash = 3;
        hash = 29 * hash + (this.login != null ? this.login.hashCode() : 0);
        hash = 29 * hash + (this.password != null ? this.password.hashCode() : 0);
        return hash;
    }
}
